package com.springBoot.controller;

import com.springBoot.entity.DataEntity;
import com.springBoot.service.DataOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/data-operation")
public class DataOperationController {

    @Autowired
    private DataOperationService dataOperationService;

    @PostMapping("/batch-update")
    public List<Map<String, String>> batchUpdateData(@RequestBody List<Map<String, String>> dataList) throws ExecutionException, InterruptedException {
        return dataOperationService.batchUpdate(dataList).get();
    }

    @PostMapping("/batch-delete")
    public void batchDelete(@RequestBody List<DataEntity> dataEntityList){
        this.dataOperationService.batchDelete(dataEntityList);
    }

    @PostMapping("/batch-insert")
    public List<Map<String, String>> batchInsertData(@RequestBody List<Map<String, String>> dataList) throws ExecutionException, InterruptedException {
        return dataOperationService.batchInsert(dataList).get();
    }
}
